from openai import OpenAI
from typing import List, Dict, Any
from .llm_interface import LLMInterface

class OpenAILLM(LLMInterface):
    """OpenAI模型实现"""
    
    def __init__(self, config: Dict[str, Any]):
        self.client = OpenAI(
            api_key=config.get("api_key"),
            base_url=config.get("base_url", "https://api.openai.com/v1")
        )
        self.model_name = config.get("model_name", "gpt-3.5-turbo")
        
    def chat(self, messages: List[Dict[str, str]], **kwargs) -> str:
        """调用OpenAI API进行对话"""
        response = self.client.chat.completions.create(
            model=self.model_name,
            messages=messages,
            **kwargs
        )
        return response.choices[0].message.content
    
    def get_model_name(self) -> str:
        return self.model_name 